<script>
	import { isLoginRequired, checkLoginStatus } from '@/utils/auth.js'
	
	export default {
		onLaunch: function () {
			console.log('E租贝应用启动')
			// 加载本地字体文件，解决Android设备图标显示问题
			this.loadLocalFont()
		},
		onShow: function () {
			console.log('App Show')
		},
		onHide: function () {
			console.log('App Hide')
		},
		// 全局路由守卫
		onPageNotFound: function (res) {
			console.log('页面不存在', res)
			uni.reLaunch({
				url: '/pages/index/index'
			})
		},
		methods: {
			// 加载本地字体文件
			loadLocalFont() {
				// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-ALIPAY
				uni.loadFontFace({
					global: true, // 全局生效
					family: 'uicon-iconfont',
					source: 'url("/static/uicon-iconfont.ttf")',
					success() {
						console.log('本地图标字体加载成功')
					},
					fail(err) {
						console.error('本地图标字体加载失败:', err)
						// 如果本地字体加载失败，回退到CDN
						uni.loadFontFace({
							global: true,
							family: 'uicon-iconfont',
							source: 'url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")',
							success() {
								console.log('CDN图标字体加载成功')
							},
							fail(err2) {
								console.error('CDN图标字体加载也失败:', err2)
							}
						})
					}
				})
				// #endif
			}
		}
	}
</script>

<style lang="scss">
/* 导入uView样式 - 传统uni-app项目 */
@import "@/uni_modules/uview-plus/index.scss";
/* 导入项目SCSS变量 */
@import "@/uni.scss";

/* ==================== 临时uView基础样式 ==================== */
/* 基础样式，确保uView组件能正常显示 */
page {
  box-sizing: border-box;
}

.u-flex {
  display: flex !important;
  flex-direction: row;
}

.u-flex-1 {
  flex: 1;
}

.u-flex-column {
  flex-direction: column !important;
}

.u-justify-center {
  justify-content: center;
}

.u-justify-between {
  justify-content: space-between;
}

.u-align-center {
  align-items: center;
}

.u-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12rpx 24rpx;
  border-radius: 6rpx;
  font-size: 28rpx;
  line-height: 1;
}
view, text, image, button, input, textarea, scroll-view, swiper, navigator {
  box-sizing: border-box;
}
/* 页面基础样式 */
page {
  background-color: $bg-secondary;
  color: $text-primary;
  font-size: $font-size-base;
  line-height: $line-height-base;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 清除默认样式 */
view, text, image, button {
  padding: 0;
  margin: 0;
  border: 0;
}

/* 统一按钮样式 */
button {
  background: none;
  border: none;
  outline: none;
  font-size: inherit;
  color: inherit;
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 图片默认样式 */
image {
  display: block;
  border: 0;
  max-width: 100%;
  height: auto;
}

/* 输入框样式重置 */
input, textarea {
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

/* ==================== 通用组件样式 ==================== */
/* 页面容器 */
.page-container {
  min-height: 100vh;
  background: $bg-secondary;
  padding: $page-padding;
  padding-bottom: calc(env(safe-area-inset-bottom) + 40rpx);
}

/* 内容卡片 */
.content-card {
  background: $bg-primary;
  border-radius: $border-radius-md;
  padding: $card-padding;
  margin-bottom: $section-margin;
  box-shadow: $box-shadow-light;
}

/* 卡片标题 */
.card-title {
  font-size: $font-size-md;
  font-weight: $font-weight-bold;
  color: $text-primary;
  margin-bottom: $margin-md;
  padding-bottom: $padding-base;
  border-bottom: 1rpx solid $border-color;
}

/* 列表项 */
.list-item {
  display: flex;
  align-items: center;
  padding: $padding-xl 0;
  border-bottom: 1rpx solid $border-color;
  transition: $transition-fast;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:active {
  background: $bg-light-gray;
  transform: scale(0.98);
}

/* 状态标签 */
.status-tag {
  padding: 6rpx 16rpx;
  border-radius: $border-radius-base;
  font-size: $font-size-sm;
  font-weight: $font-weight-medium;
  text-align: center;
  min-width: 120rpx;
}

.status-tag.available {
  background: $status-available;
  color: $status-available-text;
}

.status-tag.unavailable {
  background: $status-unavailable;
  color: $status-unavailable-text;
}

.status-tag.pending {
  background: $status-pending;
  color: $status-pending-text;
}

.status-tag.confirmed {
  background: $status-confirmed;
  color: $status-confirmed-text;
}

.status-tag.completed {
  background: $status-completed;
  color: $status-completed-text;
}

.status-tag.cancelled {
  background: $status-cancelled;
  color: $status-cancelled-text;
}

/* 价格标签 */
.price-tag {
  color: $price-color;
  font-weight: $font-weight-bold;
  font-size: $font-size-md;
}

.price-tag-large {
  color: $price-color;
  font-weight: $font-weight-bold;
  font-size: $font-size-xl;
}

/* 用户头像 */
.user-avatar {
  border-radius: $border-radius-circle;
  border: 4rpx solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.user-avatar.size-sm {
  width: $avatar-size-sm;
  height: $avatar-size-sm;
}

.user-avatar.size-base {
  width: $avatar-size-base;
  height: $avatar-size-base;
}

.user-avatar.size-lg {
  width: $avatar-size-lg;
  height: $avatar-size-lg;
}

/* 设备图片 */
.device-image {
  width: $device-image-size;
  height: $device-image-size;
  border-radius: $device-image-radius;
  overflow: hidden;
}

.device-image-large {
  width: 100%;
  height: 400rpx;
  border-radius: $border-radius-md;
  overflow: hidden;
}

/* 渐变背景 */
.gradient-bg {
  background: $primary-gradient;
}

/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 40rpx;
  text-align: center;
}

.empty-image {
  width: 200rpx;
  height: 200rpx;
  margin-bottom: $margin-xl;
  opacity: 0.6;
}

.empty-text {
  font-size: $font-size-base;
  color: $text-tertiary;
  margin-bottom: $margin-xl;
}

/* 加载状态 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80rpx;
}

.loading-text {
  margin-top: $margin-md;
  color: $text-tertiary;
  font-size: $font-size-sm;
}

/* 底部操作栏 */
.bottom-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: $bg-primary;
  border-top: 1rpx solid $border-color;
  padding: $padding-md;
  padding-bottom: calc(env(safe-area-inset-bottom) + #{$padding-md});
  z-index: $z-index-popup;
}

/* 标签页 */
.tab-container {
  display: flex;
  background: $bg-primary;
  border-bottom: 1rpx solid $border-color;
  overflow-x: auto;
}

.tab-item {
  flex-shrink: 0;
  padding: $padding-lg $padding-xl;
  font-size: $font-size-base;
  color: $text-secondary;
  text-align: center;
  border-bottom: 4rpx solid transparent;
  transition: $transition-base;
  white-space: nowrap;
}

.tab-item.active {
  color: $primary-color;
  border-bottom-color: $primary-color;
  font-weight: $font-weight-bold;
}

/* ==================== 动画效果 ==================== */
/* 渐入动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(30rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn $animation-duration-base ease-out;
}

/* 缩放动画 */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.scale-in {
  animation: scaleIn $animation-duration-base ease-out;
}

/* 点击反馈 */
.tap-highlight {
  transition: $transition-fast;
}

.tap-highlight:active {
  opacity: 0.8;
  transform: scale(0.98);
}

/* ==================== 响应式设计 ==================== */
/* 小屏幕优化 */
@media (max-width: 750rpx) {
  .page-container {
    padding: $padding-base;
  }
  
  .content-card {
    padding: $padding-md;
  }
  
  .card-title {
    font-size: $font-size-base;
  }
}

/* 安全区域适配 */
.safe-area-bottom {
  padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
}

.safe-area-top {
  padding-top: calc(env(safe-area-inset-top) + 20rpx);
}

/* ==================== 深色模式支持 ==================== */
/* 暗色主题变量（预留） */
@media (prefers-color-scheme: dark) {
  // 预留暗色模式样式
  // page {
  //   background-color: #1a1a1a;
  //   color: #ffffff;
  // }
}

/* ==================== uView组件自定义样式 ==================== */
/* 自定义uView按钮样式 */
.u-button {
  border-radius: $border-radius-base !important;
  font-weight: $font-weight-medium !important;
}

.u-button--primary {
  background: $primary-gradient !important;
  border: none !important;
}

/* 自定义uView输入框样式 */
.u-input {
  border-radius: $border-radius-base !important;
  background: $bg-tertiary !important;
  border: 1rpx solid $border-color !important;
}

.u-input--focus {
  border-color: $primary-color !important;
}

/* 自定义uView卡片样式 */
.u-card {
  border-radius: $border-radius-md !important;
  box-shadow: $box-shadow-light !important;
}

/* ==================== 图标字体修复 ==================== */
/* 确保uview-plus图标字体正确加载和显示 */
@font-face {
  font-family: 'uicon-iconfont';
  src: url('/static/uicon-iconfont.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* 强制应用字体到uview图标 */
.u-iconfont {
  font-family: 'uicon-iconfont' !important;
  font-style: normal !important;
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
}

/* Android设备字体渲染优化 */
/* #ifdef APP-PLUS-NVUE */
.u-icon__icon {
  font-family: 'uicon-iconfont';
  font-style: normal;
}
/* #endif */
</style>